package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.TongHuaLogBean;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;
import org.yczbj.ycrefreshviewlib.swipe.OnSwipeMenuListener;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fgs
 * @date 2020/9/10
 * @description
 **/
public class LiuLanListAdapter extends RecyclerArrayAdapter<TongHuaLogBean.RecordsDTO> {
    private boolean isEdit;


    public LiuLanListAdapter(Context context) {
        super(context);
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private OnSwipeMenuListener listener;

    public void setOnSwipeMenuListener(OnSwipeMenuListener listener) {
        this.listener = listener;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new TongHuaListViewHolder(parent, R.layout.item_liulan_layout);
    }

    public List<TongHuaLogBean.RecordsDTO> getSelectedMessage() {
        List<TongHuaLogBean.RecordsDTO> messageInfoList = new ArrayList<>();
//        for (TongHuaLogBean.RecordsDTO messageInfo : getAllData()) {
//            if (messageInfo.isChecked) {
//                messageInfoList.add(messageInfo);
//            }
//        }
        return messageInfoList;
    }


    private class TongHuaListViewHolder extends BaseViewHolder<TongHuaLogBean.RecordsDTO> {

        private TextView tv_tel_text;
        private TextView tv_tel_people_text;
        private TextView tv_hoyuan_text;
        private TextView tv_yonghu_text;
//        private TextView tv_weizhi_text;
        private TextView tv_shifa_text;
        private TextView tv_mudi_text;



        public TongHuaListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            tv_tel_text = getView(R.id.tv_tel_text);
            tv_tel_people_text = getView(R.id.tv_tel_people_text);
            tv_hoyuan_text = getView(R.id.tv_hoyuan_text);

            tv_yonghu_text = getView(R.id.tv_yonghu_text);
//            tv_weizhi_text = getView(R.id.tv_weizhi_text);
            tv_shifa_text = getView(R.id.tv_shifa_text);
            tv_mudi_text = getView(R.id.tv_mudi_text);


//            addOnClickListener(R.id.item_message_list_itemLinearLayout);
        }

        @Override
        public void setData(TongHuaLogBean.RecordsDTO data) {
            super.setData(data);
            int position = LiuLanListAdapter.this.getPosition(data);


            tv_tel_text.setText( data.getBillno());
            tv_tel_people_text.setText( data.getUsername());
            if ("1".equals(data.getType())){
                tv_hoyuan_text.setText( "货源大厅");
            }else {
                tv_hoyuan_text.setText("通知");
            }
            tv_yonghu_text.setText( data.getTelphone());

//            tv_weizhi_text.setText( data.getLocation());
            String dressShiFa = data.getDeliverprovince() + data.getDelivercounty() + data.getDelivercity();
            tv_shifa_text .setText( dressShiFa);
            String dressMuDi = data.getDestinationprovince() + data.getDestinationcounty() + data.getDestinationcity();
            tv_mudi_text.setText( dressMuDi);

//            checkBoxFrameLayout.setVisibility(isEdit ? View.VISIBLE : View.GONE);
//            swipeMenu.setSwipeEnable(!isEdit);
//
//            titleTextView.setText(data.title);
//            timeTextView.setText(data.createTime);
//            contentTextView.setText(data.content);
//            if (data.remindFlag == 1) {
//                imageView.setBackgroundResource(R.mipmap.icon_message_read);
//            } else {
//                imageView.setBackgroundResource(R.mipmap.icon_message_unread);
//            }
//
//            showCheckStatus(data.isChecked);
//
//            deleteFrameLayout.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (listener != null) {
//                        listener.toDelete(getDataPosition());
//                    }
//                }
//            });
//
//            checkBoxFrameLayout.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//
//                    data.isChecked = !data.isChecked;
//                    showCheckStatus(data.isChecked);
//                    notifyItemChanged(position);
//                }
//            });

        }
//        private void showCheckStatus(boolean isChecked) {
//            if (isChecked){
//                checkImageView.setBackgroundResource(R.mipmap.icon_checked);
//            }else {
//                checkImageView.setBackgroundResource(R.mipmap.icon_unchecked);
//            }
//        }
    }



}
